/**
 * @FileName: LoginRequest.java
 * @Package:com.bdtop.dbl.server.apis
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-16
 * @version V1.0
 */

package com.bdtop.dbl.server.request;

import com.bdtop.dbl.server.response.LoginResponse;
import com.bdtop.dbl.thirdparty.asynchttp.HttpPostRequest;
import com.bdtop.dbl.thirdparty.asynchttp.RequestCallback;
import com.bdtop.dbl.utils.Constants;
import com.bdtop.dbl.utils.DBLDebug;
import com.google.gson.Gson;

/**
 * @ClassName: LoginRequest
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-16
 */
public class LoginRequest extends HttpPostRequest {

    /**
     * @param callback
     */
    public LoginRequest(RequestCallback callback) {
        super(callback);
        getRequestParams().add(Constants.COMMAND, Constants.CMD_LOGIN);
    }

    public void setParams(String phoneNumber, String password) {
        getRequestParams().add(Constants.PARAM_USER_NAME, phoneNumber);
        getRequestParams().add(Constants.PARAM_PWD, password);

    }

    @Override
    public Object parse(String responseString) {
        DBLDebug.logd("LoginRequest response = " + responseString);

        Gson gson = new Gson();
        LoginResponse response = gson.fromJson(responseString, LoginResponse.class);

        return response;
    }

    @Override
    protected String getUrl() {
        return Constants.SERVER_ADDRESS;
    }

}
